package com.example.swordkotlin

object Test23 {

    @JvmStatic
    fun main(args: Array<String>) {
        val pre = intArrayOf(1, 2, 4, 7, 3, 5, 6, 8)
        val vin = intArrayOf(4, 7, 2, 1, 5, 3, 8, 6)

        for (i in 0..3) {
            println(i)
        }

        for (i in 0 until 3) {
            println("---$i")
        }
    }

    class ListNode(var `val`: Int, var next: ListNode? = null)


    /**
     * 给一个长度为n链表，若其中包含环，请找出该链表的环的入口结点，否则，返回null。
     */

    fun EntryNodeOfLoop(pHead: ListNode?): ListNode? {
        // write code here
        var slow = pHead
        var fast = pHead

        while (fast?.next != null && fast != null) {
            fast = fast?.next?.next
            slow = slow?.next
            if (fast == slow) {
                fast = pHead
                while (fast != slow) {
                    fast = fast?.next
                    slow = slow?.next
                }
                return fast
            }
        }
        return null
    }
}